﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace Elvex
{
    public class UIPanel : MonoBehaviour
    {
        public object ID { get; set; }

        Dictionary<string, GameObject> m_hintObject = new Dictionary<string, GameObject>();

        private void Start()
        {
            Elvex.Instance.OnUIPanelHintChanged += DisposeHint;

            if(Elvex.Instance.UIConfiguration.PanelConfigures.TryGetValue(ID, out var panelcfg))
            {
                // 处理红点提示信息
                foreach (var item in panelcfg.HintConfigures)
                {
                    if(null == item.Value.CheckFunc)
                    {
                        continue;
                    }
                    var go = gameObject.FindChild(item.Key).gameObject;
                    //item.Value.GetHashCode();
                    if( null == go )
                    {
                        continue;
                    }
                    m_hintObject.Add(item.Key, go);

                    int hintnum = item.Value.CheckFunc.Invoke();
                    if(hintnum >= 0 )
                    {
                        // 显示红点提示信息
                    }
                }
            }
        }
        
        public void DisposeHint(object hintid)
        {
            if (Elvex.Instance.UIConfiguration.PanelConfigures.TryGetValue(ID, out var panelcfg))
            {
                // 处理红点提示信息
                foreach (var item in panelcfg.HintConfigures)
                {
                    if(hintid == item.Value.HintID )
                    {
                        if (m_hintObject.TryGetValue(item.Key, out var go))
                        {
                            // 检查红点信息
                        }
                    }
                }
            }
        }

        private void OnDestroy()
        {
            Elvex.Instance.OnUIPanelHintChanged -= DisposeHint;
        }
    }
}
